﻿using System;
using System.Collections.Generic;
using System.Linq;

using System.Web.Mvc;
using Prodma.DataAccess.Database;
using Prodma.DataAccess.Models;
using Prodma.DataAccess.Helper.Enumerators;

namespace Prodma.DataAccess.DataService.ListService
{
    public class CityList
    {
        private static DataContext context = new DataContext();

        public static SelectList GetList()
        {
            DataContext context = new DataContext();
            using (context)
            {
                int stateId = Convert.ToInt32(State.Active);
                var list = (from city in context.tb_City
                            select city).OrderBy(x => x.Name);
                SelectList selectList = new SelectList(list.ToDictionary(x => x.Id, z => z.Name), "Key", "Value");

                return selectList;
            }
        }
        public static SelectList GetList(int id)
        {
            int stateId = Convert.ToInt32(State.Active);
            DataContext context = new DataContext();
            using (context)
            {
                var list = (from city in context.tb_City
                            select city).OrderBy(x => x.Name);
                SelectList selectList = new SelectList(list.ToDictionary(x => x.Id, z => z.Name), "Key", "Value", id);

                return selectList;
            }
        }
    }
}
